package com.dyh.quickdemozwei.pipe0825;

import com.google.common.collect.Lists;

import java.util.List;

public class App {
    public static void main(String[] args) {
        t1();

    }


    public static void t2(){
        PipeLineBootStrap bs = new PipeLineBootStrap();


        PipeLineNode n1 = new PipeLineNode(ctx->{
            ctx.setVal("list", Lists.newArrayList(1,2,3));
            return 1;
        });



        PipeLineNode l21 = new PipeLineNode(ctx->{
            List list = ctx.getVal("list");
            for (Object o : list) {
                System.out.println(o);
            }
            return 1;
        });



    }

    public static void t1(){
        PipeLineBootStrap bs = new PipeLineBootStrap();



        bs.addLast(new PipeLineNode(context -> 1) {
            @Override
            public Object work(PipeLineContext context) {
                return 1;
            }
                })
                .addLast(new AbstractPipeLineNode() {
                    @Override
                    public Object work(PipeLineContext context) {
                        int i = context.getLastResult();
                        context.setVal("k1","v1");
                        return i+1;
                    }
                })
                .addLast(new AbstractPipeLineNode() {
                    @Override
                    public Object work(PipeLineContext context) {
                        if (1==1)
                            context.end = true;
                        System.out.println(""+context.getVal("k1"));
                        context.fireEnd();
                        return null;
                    }
                })
                .addLast(new AbstractPipeLineNode() {
                    @Override
                    public Object work(PipeLineContext context) {
                        int i =context.getLastResult();
                        return i+1;
                    }
                });

        PipeLine pipeLine = bs.build();
        PipeLineContext context = pipeLine.createContext();
        pipeLine.work(context);

        System.out.println();


    }
}
